package com.kgc.common;

import com.alibaba.fastjson2.JSON;
import lombok.Getter;
import lombok.Setter;

/**
 * @author cp
 * @time 2024/3/29 9:41
 * @describe 返回json格式结果
 */
@Getter
@Setter
public class Result {
    private String code; //标识码
    private String msg; //响应消息体
    private int count; //返回记录数
    private Object data; //响应数据体

    public Result() {
    }

    public Result(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result(String code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Result(String code, String msg, int count, Object data) {
        this.code = code;
        this.msg = msg;
        this.count = count;
        this.data = data;
    }


    public static String success(String code, String msg, Object o) {
        Result result = new Result(code, msg, o);
        return JSON.toJSONString(result);
    }

    public static String success(String code, String msg, int count, Object o) {
        Result result = new Result(code, msg, count, o);
        return JSON.toJSONString(result);
    }

    public static String success(String code, String msg) {
        Result result = new Result(code, msg);
        return JSON.toJSONString(result);
    }

    @Override
    public String toString() {
        return "Result{code = " + code + ", msg = " + msg + ", count = " + count + ", data = " + data + "}";
    }
}